home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / examples / dltest1.c < prev    next >
C/C++ Source or Header  |  1994-09-20  |  2KB  |  65 lines

  1. /* **************************************************************
  2.  * dltest1.c: A dynamic linking example (1). Rather trivial, since
  3.  *            it just re-implements strtod, but it does illustrate
  4.  *            a few points, such as how to get arguments, in
  5.  *            particular how to deal with string arguments.
  6.  * ************************************************************** */
  7.  
  8. #include "rlab.h"
  9. #include "symbol.h"
  10. #include "mem.h"
  11. #include "list.h"
  12. #include "btree.h"
  13. #include "bltin.h"
  14. #include "scop1.h"
  15. #include "matop1.h"
  16. #include "matop2.h"
  17. #include "r_string.h"
  18. #include "util.h"
  19. #include "mathl.h"
  20. #include "function.h"
  21.  
  22. #include <math.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <errno.h>
  26.  
  27. void
  28. RStrtod (return_ptr, n_args, d_arg)
  29.      VPTR *return_ptr;
  30.      int n_args;
  31.      Datum *d_arg;
  32. {
  33.   int i, nel;
  34.   ListNode *SM;
  35.   Matrix *m, *new = 0;
  36.  
  37.   /* Check n_args */
  38.   if (n_args != 1)
  39.     error_1 ("strtod: requires 1 argument", 0);
  40.  
  41.   SM = bltin_get_string_matrix ("strtod", d_arg, 1);
  42.   m = (Matrix *) e_data (SM);
  43.  
  44.   switch (MTYPE (m))
  45.   {
  46.   case REAL:
  47.   case COMPLEX:
  48.     error_1 ("strtod: input must be string", matrix_GetName (m));
  49.     break;
  50.   case STRING:
  51.     new = matrix_Create (MNR (m), MNC (m));
  52.     nel = MNR (m) * MNC (m);
  53.     for (i = 0; i < nel; i++)
  54.       MATrv (new, i) = strtod (MATsv (m, i), (char **) 0);
  55.     break;
  56.   default:
  57.     error_1 ("strtod: invalid matrix type", 0);
  58.     break;
  59.   }
  60.  
  61.   remove_tmp_destroy (SM);
  62.   *return_ptr = (VPTR) new;
  63.   return;
  64. }
  65.